AI Lessons
Lesson 19: Training an image classifier in Teachable Machine

Purpose: To learn how to train a custom AI image classification model using Teachable Machine, and understand what makes a trained model good or poor through dataset variation and testing.

No. of Classes

1 - (Time : 1 hour 30 minutes, Laptops/desktops : 10, Students strength : 15 to 20).

Materials Required

Laptop / Desktop with Internet connection / Wi-Fi.

Webcam.

Prior knowledge
  • Understanding image classification vs. object detection
  • Basic knowledge of supervised learning (labels and examples)
  • Managing browser webcam permissions
Exercises

Exercise (1) - Teachable Machine Image Project

Step 1 - Teachable Machine Image Project



  • Open Teachable Machine Image Project .
  • Create two distinct classes (e.g., "Owner" and "Background", or "Pen" and "No Pen").
  • Hold down the webcam button to record 30–50 image samples for each class.
  • Train the model and test live predictions in the preview panel.


Step 2 - Creating a "Weak" Model (Failure Modes)



  • Create a new model, but intentionally limit the training data: record only 5 samples for Class A, and capture them from a single angle or in dark lighting.
  • Test the weak model by changing your position, distance, or room lighting. Record where the model fails or makes confident wrong guesses.


Step 3 - Iterative Improvement & Bias Testing



  • Add a third class (e.g. "Stranger" or "Owner 2") with significantly fewer samples than the original classes to observe dataset imbalance.
  • Retrain the model with varied samples (different angles, lighting, background changes) and equalize sample counts across all classes.
  • Compare the confidence scores before and after retraining on unseen test inputs.

Solutions



Teacher's Instruction:
  1. Demonstrate Model Workflow (Step 1):
    • Show how to create classes, record webcam frames, and run the browser-based training process.
    • Emphasize that the AI relies on visual patterns (colors, textures, shapes) rather than "knowing" who or what an object actually is.
  2. Highlight "Background Shortcuts" and Overfitting (Step 2):
    • Demonstrate moving around, tilting your head, and changing distances during sample collection so the model learns the subject better instead of the background.
  3. Guide Dataset Imbalance & Bias Discussion (Step 3):
    • Demonstrate dataset bias by giving one class 100 images and another class only 5 images. Show how the model heavily favors the class with more data.
    • Guide students to fix the imbalance by collecting diverse, equal-sized datasets across all classes.
  4. Test your trained model on new samples that are not present in the training data set
  5. Points to Ponder:
    • If an AI model is 99% confident that a book is a phone, why shouldn't we trust high confidence scores blindly?
    • What happens if you present an object to your model that belongs to neither of your trained classes (e.g., showing a shoe to a model only trained on "Apple" and "Banana")?